SIFT Demo

Loi Cheng DGMD S-17 2020 Summer

In [2]:
import cv2
import numpy as np
import matplotlib.pyplot as plt
from Sift_Operations import *

print("Make Sure that both the images are in the same folder")
#x = input("Enter First Image Name: ")
x="1.png"
Image1 = cv2.imread(x)
#y = input("Enter Second Image Name: ")
y="2.png"
Image2 = cv2.imread(y)
Image1_gray = cv2.cvtColor(Image1, cv2.COLOR_BGR2GRAY)
Image2_gray = cv2.cvtColor(Image2, cv2.COLOR_BGR2GRAY)
Image1_key_points, Image1_descriptors = extract_sift_features(Image1_gray)
Image2_key_points, Image2_descriptors = extract_sift_features(Image2_gray)
print('Displaying SIFT Features')
showing_sift_features(Image1_gray, Image1, Image1_key_points);
norm = cv2.NORM_L2
bruteForce = cv2.BFMatcher(norm)
matches = bruteForce.match(Image1_descriptors, Image2_descriptors)
matches = sorted(matches, key=lambda match: match.distance)

matched_img = cv2.drawMatches( Image1, Image1_key_points, Image2, Image2_key_points, matches[:100], Image2.copy())
plt.figure(figsize=(100, 300))
plt.imshow(matched_img)
Make Sure that both the images are in the same folder
Displaying SIFT Features
Out[2]:
<matplotlib.image.AxesImage at 0x7fa2d4dc5810>

Comment

The SIFT code was able to match the 2 buildings fairly well between the 2 pictures. Lines from the tower of one image is linked to the same tower in the other. The same matching is evidient for the larger building on the left as well.

In [ ]: